<!-- 项目管理完成 -->
<template>
  <div>
    <el-dialog :title="completeData.title" :visible.sync="completeData.showModal" width="650px" top="5vh">
      <el-form label-width="100px" :model="data" ref="update" :rules="rules" v-loading="showLoading" element-loading-text="数据加载中">
        <el-row>
          <el-col :offset="3" :span="18">
            <el-form-item label="项目总收益" prop="totalIncomeAmt">
              <el-input type="number" size="medium" placeholder="请输入项目总收益" v-model="data.totalIncomeAmt"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- 底部按钮开始 -->
      <span slot="footer" class="dialog-footer">
        <el-button size="medium" type="primary" @click="sub">提交</el-button>
        <el-button size="medium" @click="completeData.showModal = false">取消</el-button>
      </span>
      <!-- 底部按钮结束 -->
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: ['completeData'],
  data () {
    let validAmt = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入项目总收益"));
      } else if (value <= 0) {
        callback(new Error("项目总收益不能小于0"));
      } else {
        callback();
      }
    };
    return {
      showLoading: false,//是否显示loading
      title: '',//标题
      //需要提交的数据
      data: {
        id: '',
        totalIncomeAmt: '',
      },
      //表单校验
      rules: {
        totalIncomeAmt: [
          { required: true, validator: validAmt, trigger: "blur" }
        ],
      }
    }
  },
  methods: {
    //提交
    sub () {
      this.$refs['update'].validate(async (valid) => {
        if (valid) {
          this.showLoading = true;
          this.data.id = this.completeData.id;
          let result = await this.request.httpRequest('PUT', '/project/complete', this.data)
          if (result.code == 200) {
            this.completeData.showModal = false
            this.$message({ type: 'success', message: result.msg })
            this.$emit('close')
          } else {
            this.$message({ type: 'error', message: result.msg })
          }
          this.showLoading = false
        }
      })
    },
  }
}
</script>
